/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package  ua.kiev.gcore.string{	
	import flash.events.Event;
	import flash.text.TextField;
	
	public class TextModificatory
	{
		//public static const sygOnly:String = "/ /~ /! /@ /# /$ /% /^ /& /* /( /) /_ /- /+ /= /| /{ /} /: // /. /, /< /> /[ /]";
		//public static const abcOnly:String = "a-z A-Z а-я А-Я 0-9 /і /І /ї /Ї /є /Є /Ё /ё";
		//public static const numOnly:String = "0-9";
		
		public static function checkSymbol(e:Event):void{
			var textFild:TextField = e.currentTarget as TextField;
			var text:String = textFild.text;			 
			var result:String = text.replace('"',"").toString();			
			textFild.text = result;
		}
		
		public static function replace(str:String, symbol:String = " ", replaceTo:String = "*" ):String{
			var newStr:String="";
			var arr:Array = str.split(symbol);
			for each(var i:String in arr){			
				newStr+= i+replaceTo;
			}
			newStr = newStr.slice(0, newStr.length - replaceTo.length);		
			return newStr;
		}
		
		public static function setLinck(str:String, begin:String = "<", end:String = ">", func:String = ""):String{
			var tmp:String=str;
			var arr:Array = str.split(begin);
			if(arr.length>1){				
				var arr2:Array = arr[1].split(end);
				if(arr2.length>1){
					var str1:String = arr[0];
					var str2:String = arr2[0].split(" ")[0];
					var str3:String = arr2[0].split(" ")[1]+" "+arr2[0].split(" ")[2];
					var str4:String = arr2[1];	
					tmp=str1+"<font color='#0000ff'><u><a href ='event:"+str2+"'>"+str3+"</a></u></font>"+str4;
				}
			}
			return tmp;	
		}
		
		public static function getFormatTimeFull($iSecondsLeft:int) : String{
			var result			: String = "";
			
			var days			:int = Math.floor($iSecondsLeft / (3600*24));
			var hours			: int = Math.floor(($iSecondsLeft%(3600*24))/3600);
			var min				: int = Math.floor(($iSecondsLeft%3600)/60);
			var sec				: int = $iSecondsLeft%60;			
			
			if (hours > 24) {
			result = Math.round(hours / 24) + " д";
			}		
			if(days > 0){
			
			}else if(hours > 0) {
			result = hours.toString() + " ч " + min + " мин";
			} else 
			if (int(min) > 0) {
			result = min + " мин ";// + sec + " сек";
			}  else {
			//result = min + " мин ";
			result = sec + " сек";			
			}
			
			//Logger.DEBUG("Time>>>>>: "+result);
			return result;
		}
		public static function getNonLabelTimeFormatMin(iTime:int) : String{
			var _iSec:int = iTime % 60; //seconds
			var _sSec:String = (_iSec < 10) ? "0" + _iSec.toString() : _iSec.toString();
			var _iMin:int = int(iTime / 60); //Minutes
			var _sMin:String = (_iMin < 10) ? "0" + _iMin.toString() : _iMin.toString();
			
			return _sMin + " : " + _sSec;
		}
		// 00:00:00
		public static function getNonLabelTimeFormatFull(iTime:int):String {
			var _iSec:int = iTime % 60; //seconds
			var _sSec:String = (_iSec < 10) ? "0" + _iSec.toString() : _iSec.toString();
			var _iMin:int = int(iTime / 60) % 60; //Minutes
			var _sMin:String = (_iMin < 10) ? "0" + _iMin.toString() : _iMin.toString();
			var _iHours:int = int(iTime / 3600) % 24; //Hours
			var _sHours:String = (_iHours < 10000) ? "0" + _iHours.toString() : _iHours.toString();
			return _sHours + ":" + _sMin + ":" + _sSec;
		}
		
		public static function strReplace(replaceWith:String, replace:String, original:String):String {
			var array:Array = original.split(replaceWith);
			return array.join(replace);
		}
		public static function _hexToHtml(original:String):String {
			var result:String = original.replace('0x', "#");
			return result;
		}
		public static function _htmlToHEX(original:String):uint {
			var result:uint = uint(original.replace('#', "0x"));
			return result;
		}
		
		public static function strMultipleReplace(original:String, ...statements):String {
			var result:String = original;
			for (var i:int = 0; i < statements.length; i++) {
				var pattern:String = "{" + i + "}";
				result = strReplace(pattern, statements[i], result);
			}
			return result;
		}
	}
}